<?php
defined('IN_SITE') or exit('Access Denied');

/*require_once 'tree.class.php';
require_once MOD_ROOT.'page/page.class.php';
require_once MOD_ROOT.'content/content.class.php';

$tree = new tree;
$pageid = isset($pageid) ? intval($pageid) : 0;
$cat = new page();
$c = new content();*/

/* debug by aming */
if($_GET['debug']){
	if($pageid){
		$debugs = $db->get_one("select * from ".DB_PRE."page where pageid = '$pageid'"); 
	}
	else if($catdir){
		$debugs = $db->get_one("select * from ".DB_PRE."page where catdir = '$catdir' and parentdir = '$parentdir'");
	}
	dump($debugs);
}

switch($action)
{
	default:
	
		if($pageid){
			$result = $db->get_one("select * from ".DB_PRE."page where pageid = '$pageid'"); 
		}
		else if($catdir){
			$result = $db->get_one("select * from ".DB_PRE."page where catdir = '$catdir' and parentdir = '$parentdir'");
		}
		else{
			showmessage('no pageid');
		}
		extract($result); 
		
		$setting = string2array($setting);
		extract($setting);
		
		/*$C = cache_read('page_'.$pageid.'.php');
		extract($C);*/
		
		
		$arrparentid = explode(',', $arrparentid);
		$parentid = $arrparentid[1];
		
		$head['title'] = $catname.'_'.$SETTING['sitename'];
		$head['keywords'] = $meta_keywords;
		$head['description'] = $meta_description;
		
		$ttl = $child == 1 ? CACHE_PAGE_page_TTL : CACHE_PAGE_LIST_TTL;
		header('Last-Modified: '.gmdate('D, d M Y H:i:s', TIME).' GMT');
		header('Expires: '.gmdate('D, d M Y H:i:s', TIME + $ttl).' GMT');
		header('Cache-Control: max-age='.$ttl.', must-revalidate');
		
		
		include template($template);
		cache_page($ttl);exit();
	break;
	
	case 'load':
		
		if($modelid)
		{
			$page = submodelcat($modelid);
		}
		$str = '<select onchange="$(\'#pageid\').val(this.value);this.disabled=true;page_load(this.value);"><option value="0">'.$LANG['please_select'].'</option>';
		$options = '';
		foreach($page as $i=>$v)
		{
			if((isset($id) && $v['parentid'] == $id) || (isset($module) && $v['module'] == $module))  $options .= '<option value="'.$i.'">'.$v['catname'].'</option>';
		}
		if(empty($options)) exit;
		$str .= $options.'</select>';
		
		echo $str;
	break;
	
	/*default:
		include template('page.html');
	break;*/
}
?>